package My.Nhom2.ServiceSearch;

import java.util.ArrayList;
import android.content.Context;


/**
 * The Class DataRetrieve.
 */
public class DataRetrieve {

    /** The data helper. */
    private DatabaseHelper dataHelper;


    /**
     * Instantiates a new data retrieve.
     */
    public DataRetrieve() {
    						
    }

    /**
     * Gets the helper.
     *
     * @return Tra ve datahelper
     */
    public final DatabaseHelper getHelper() {
         return this.dataHelper;
    }

    /**
     * Connect.
     *
     * @param context de xac dinh
     */
    public final void connect(final Context context) {
    	this.dataHelper = new DatabaseHelper(context);
    }

    /**
     * Gets the data.
     *
     * @param input Chuoi nhap vao
     * @return Mang ket qua tra ve
     */
    /*public final ArrayList<DataService> getData(final String input) {
    	ArrayList<DataService> datas = new ArrayList<DataService>();
    	ArrayList<DataService> tData;
    	ArrayList<String> strs = indentifyInput(input);
    	int n = strs.size();
        for (int i = 0; i < n; i++) {
    		tData = dataHelper.getQuery(strs.get(i));
    		sumNotDuplicate(datas, tData);
    	}

    	return datas;
    }*/
    /**
     * Get data ver 2.0
     */
    public final ArrayList<DataService> getDataVer2(final String input) {
    	//ArrayList<DataService> datas = new ArrayList<DataService>();
    	ArrayList<DataService> tData;
    	ArrayList<String> strs = indentifyInput(input);
    	tData = dataHelper.getQueryVer3(strs);
    	
    	return tData;
    }
    /**
     * Sum not duplicate.
     *
     * @param arr1 Mang thu nhat chua ket qua ghep
     * @param arr2 Mang thu hai
     */
    /*public final void sumNotDuplicate(final ArrayList<DataService> arr1,
    		final ArrayList<DataService> arr2) {
    	int sizeOfArr1 = arr1.size();
    	int sizeOfArr2 = arr2.size();
    	boolean notFound;
    	for (int i = 0; i < sizeOfArr2; i++) {
    		notFound = true;
    		for (int j = 0; j < sizeOfArr1; j++) {
    			if (arr2.get(i).maDuLieu == arr1.get(j).maDuLieu) {
    				notFound = false;
    				break;
    			}
    		}
    		if (notFound) {
    			arr1.add(arr2.get(i));
    		}
    	}

    }*/

    /**
     * Indentify input.
     *
     * @param input Chuoi nhap vao
     * @return Mang cai chuoi can tim kiem duoc phan tich
     */
    public final ArrayList<String> indentifyInput(final String input) {
    	ArrayList<String> strs = new ArrayList<String>();
    	char ch;
    	String str = "";
    	int i;
    	String cpyInput;
    	cpyInput = input.trim();
    	cpyInput = cpyInput.toLowerCase();
    	for (i = 0; i < cpyInput.length(); i++) {
    		ch = cpyInput.charAt(i);
    		if (ch != ' ') {
    		    str += Character.toString(ch);
    		}
    		else {
    			strs.add(str);
    			str = "";
    		}
    	}
    	//Them phan tu cuoi cung vao
    	if(str != "") {
    		strs.add(str);
    	}

    	return strs;
    }
    public ArrayList<ItemMenu> getMenuList(int MaDuLieu){
    	return dataHelper.getMenuList(MaDuLieu);
    }
}

